515C - Drazil and Factorial - CodeForces Solution


greedy math sortings *1400

Please click on ads to support us..

Python Code:

x = int(input())
n = input()

factorial = {
    2:[2],
    3:[3],
    4:[3,2,2],
    5:[5],
    6:[3,5],
    7:[7],
    8:[7,2,2,2],
    9:[7,3,3,2]
}

res = []
for i in n:
    num = int(i)
    if num != 1 and num != 0:
        res += factorial[num]

res = sorted(res,reverse = True)
s = ""
for i in res:
    s+=str(i)

print(int(s))
 		 		   	    	  	 	   		   			

C++ Code:

/* ____                       _  __                     _       _       _       
  |  _ \ _ __ ___ _ __ ___   | |/ /__ _ _ __ ___   __ _| |     | | __ _(_)_ __  
  | |_) | '__/ _ \ '_ ` _ \  | ' // _` | '_ ` _ \ / _` | |  _  | |/ _` | | '_ \ 
  |  __/| | |  __/ | | | | | | . \ (_| | | | | | | (_| | | | |_| | (_| | | | | |
  |_|   |_|  \___|_| |_| |_| |_|\_\__,_|_| |_| |_|\__,_|_|  \___/ \__,_|_|_| |_|
*/                                                                            

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef long double lld;

#define hell    1000000007
#define PI      3.141592653589793238462
#define INF     1e18
#define vi      vector<ll>
#define pb      push_back
#define ppb     pop_back
#define mii     map<ll,ll>
#define pii     pair<ll,ll>
#define mp      make_pair
#define ff      first
#define ss      second
#define all(x)  (x).begin(), (x).end()

/*____________________________________________________________________________________________________________________________________________________________________________________________________*/
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
/*____________________________________________________________________________________________________________________________________________________________________________________________________*/


void solve()
{
    ll n;
    cin>>n;
    ll a;
    cin>>a;
    mii ma;
    while(a!=0){
        ll x=a%10;
        a/=10;
        if(x==0 || x==1){
            continue;
        }
        else if(x==2 || x==3 || x==5 || x==7){
            ma[x]++;
        }
        else if(x==9){
            ma[7]++;
            ma[3]+=2;
            ma[2]++;
        }
        else if(x==8){
            ma[7]++;
            ma[2]+=3;
        }
        else if(x==6){
            ma[5]++;
            ma[3]++;
        }
        else if(x==4){
            ma[3]++;
            ma[2]+=2;
        }
    }

    if(ma[7]!=0){
        for(ll i=0;i<ma[7];i++){
            cout<<'7';
        }
    }
    if(ma[5]!=0){
        for(ll i=0;i<ma[5];i++){
            cout<<'5';
        }
    }
    if(ma[3]!=0){
        for(ll i=0;i<ma[3];i++){
            cout<<'3';
        }
    }
    if(ma[2]!=0){
        for(ll i=0;i<ma[2];i++){
            cout<<'2';
        }
    }
    cout<<endl;
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int t=1;
    // cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem